//
//  UIViewController+Present.m
//  ChangAppIconDemo
//
//  Created by Jason on 2023/7/25.
//

#import "UIViewController+Present.h"
#import <objc/runtime.h>

@implementation UIViewController (Present)

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        Method presentM = class_getInstanceMethod(self.class,@selector(presentViewController:animated:completion:));
        Method presentSwizzlingM = class_getInstanceMethod(self.class,@selector(dy_presentViewController:animated:completion:));
        method_exchangeImplementations(presentM, presentSwizzlingM);
        
    });
}

- (void)dy_presentViewController:(UIViewController*)viewControllerToPresent animated:(BOOL)flag completion:(void(^)(void))completion {
    
    if ([viewControllerToPresent isKindOfClass:[UIAlertController class]]) {
        
        UIAlertController *alertController = (UIAlertController*)viewControllerToPresent;
        
        if (alertController.title == nil && alertController.message == nil) {
            
            NSLog(@"替换图标操作");
            return;
            
        } else {
            
            [self dy_presentViewController:viewControllerToPresent animated:flag completion:completion];
            return;
            
        }
        
    }
    
    [self dy_presentViewController:viewControllerToPresent animated:flag completion:completion];
    
}

@end

